package com.itheima.app.controller;

import cn.hutool.core.date.DateUtil;
import com.itheima.app.manager.MakeFriendManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    MakeFriendManager makeFriendManager;

    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest() {
        return makeFriendManager.findTodayBest();
    }

    // 查询推荐用户列表
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return makeFriendManager.findRecommendUserByPage(pageNum, pageSize);
    }

    //推荐用户详情
    @GetMapping("/tanhua/{recommendUserId}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable Long recommendUserId) {
        return makeFriendManager.findPersonalInfo(recommendUserId);
    }

    // 查询历史访客
    @GetMapping("/movements/visitors")
    public ResponseEntity findVisitorsTop5() {
        return makeFriendManager.findVisitorsTop5();
    }

    // 上报地理位置
    @PostMapping("/baidu/location")
    public ResponseEntity saveUserLocation(@RequestBody Map<String, String> map) {
        System.out.println(DateUtil.formatDateTime(new Date()) + "-上报地址位置-" + map);

        Double longitude = Double.parseDouble(map.get("longitude"));//经度
        Double latitude = Double.parseDouble(map.get("latitude"));//纬度
        String addrStr = map.get("addrStr");

        return makeFriendManager.saveUserLocation(longitude, latitude, addrStr);
    }

    // 搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNear(String gender, Long distance) {
        return makeFriendManager.searchNear(gender, distance);
    }

    // 查看对方的陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity findStrangerQuestions(@RequestParam("userId") Long recommendUserId) {
        return makeFriendManager.findStrangerQuestions(recommendUserId);
    }
    // 卡片
    @GetMapping("/tanhua/cards")
    public ResponseEntity findCard() {
        return makeFriendManager.findCard();
    }

    //不喜欢
    @GetMapping("/tanhua/{unLikeUserId}/unlove")
    public ResponseEntity RecommendUserUnLike(@PathVariable Long unLikeUserId) {
        return makeFriendManager. RecommendUserUnLike(unLikeUserId);
    }
    //喜欢
    @GetMapping("/tanhua/{likeUserId}/love")
    public ResponseEntity RecommendUserLike(@PathVariable Long likeUserId) {
        return makeFriendManager. RecommendUserLike(likeUserId);
    }
}